package my.innodb;

import com.alibaba.innodb.java.reader.TableReader;
import com.alibaba.innodb.java.reader.TableReaderImpl;
import com.alibaba.innodb.java.reader.page.index.GenericRecord;
import com.google.common.collect.ImmutableList;

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        String createTableSql = "CREATE TABLE `l` (" +
                "  `a` int NOT NULL," +
                "  `b` int DEFAULT NULL," +
                "  `c` int DEFAULT NULL," +
                "  `d` int DEFAULT NULL," +
                "  `f` varchar(10) DEFAULT NULL," +
                "  PRIMARY KEY (`a`)," +
                "  UNIQUE KEY `uk_b` (`b`)," +
                "  KEY `idx_c` (`c`)" +
                ") ENGINE=InnoDB;";
        String ibdFilePath = Main.class.getResource("/").getPath() + "l.ibd";
        try (TableReader reader = new TableReaderImpl(ibdFilePath, createTableSql)) {
            reader.open();
            GenericRecord record = reader.queryByPrimaryKey(ImmutableList.of(0));
            Object[] values = record.getValues();
            System.out.println(Arrays.asList(values));
        }
    }
}
